package com.iworkh.spring.aop.jdkproxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 代理类
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-19
 */
public class LoggerProxy<T> {

    private T target;

    public LoggerProxy(T target) {
        this.target = target;
    }

    public T getProxy() {
        InvocationHandler handler = (proxy, method, args) -> {
            System.out.println("LoggerProxy..." + method.getName());
            method.invoke(target, args);
            return null;
        };


        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), handler);
    }

}


